package com.plugins.qiniu;

import java.io.File;

import com.alibaba.fastjson.JSONObject;
import com.qiniu.http.Response;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;

public class ImgTool {

	public static String upload(){
		
		try{
			File file = new File("img.jpg");
			Auth auth = Auth.create("ak9AVHKsroHmrJuSDmoV30HrlmAB-XLoipX8-hvX",
					"E7eAOUHEfcpB0lJipFbepjLpxd1PFY5i6jBN50rB");
			String token = auth.uploadToken("zziahui");
			UploadManager manager = new UploadManager();
			Response response = manager.put(file, System.currentTimeMillis()+".jpg", token);
			if(response.isOK()){
				JSONObject resJson = JSONObject.parseObject(response.bodyString());
				String imgKey = resJson.getString("key");
				return  "http://7xsegb.com1.z0.glb.clouddn.com/" + imgKey;
			}
			
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}
	
	public static void main(String[] args) throws Exception {
	}
}
